<?php
/*
          U1,
          LMF1Yr,
          BOOMBBBBBBq
         7BEP0PNqZBM
         B8kPFXFX0B
        YBXXSSFkSB;     APUXIN
        Bqk1k5SFNZ      Web OS
     :r0Ek5kSXSXO;
   jBBBNPkXF5uUYF:      by Apuxin Team
  BBqPkXUj7rrr;rrur
.J8FX5u7r;rr7r7r7rUi    requesthandler.service.php: Manage Requests
0UkkJ7irr7rrr7rrrrrj
PuX7;i7;r;r;rrririrL.
 7L;;rrrrriri;i;i;iL
  YL7;riri;i;iii;iL:
   ;LLrr;ri;i;irr7.
       ...... .

*/

/**
 * Description of requesthandlerservice
 *
 * @author David
 */
class requesthandler extends APUXIN_SERVICE {

    private $requests;
    private $default;

    public function __construct()
    {
        parent::__construct();
        $this->info_setName('requesthandler');
        $this->info_setDesc('Manage requesthandlers');
        $this->info_setVersion(0.1);
        $this->info_setOnlyOnce(true);
    }

    public function addHandler($name, $function)
    {
        $this->requests[$name] = $function;
    }

    public function handle()
    {
        if(isset($_POST['do']) && !empty($_POST['do']))
        {
            if(isset($this->requests[$_POST['do']]))
            {
                call_user_func_array($this->requests[$_POST['do']], array($_POST));
            }
        } else
        {
            call_user_func($this->default);
        }
    }

    public function setDefault($deffunc)
    {
        $this->default = $deffunc;
    }
}
?>
